import { Component, Input } from '@angular/core';
import { CascaderItem } from 'ng-devui';
@Component({
  selector: 'app-device-category',
  templateUrl: './device-category.component.html',
  styleUrls: ['./device-category.component.scss']
})
export class DeviceCategoryComponent {
  @Input() data: any;
  options :any=[];//部门
  EquiomentCategory={
    equipmentCategoryName: '',
    priority: null,
    parentEquipmentCategoryId: null,
  };//分类类目
  constructor(){}
  ngOnInit(): void{
    this.options = this.convertToCascaderItem(this.data.options)
    if(this.data.pathPids){
      this.EquiomentCategory.parentEquipmentCategoryId = this.data.pathPids[this.data.pathPids.length-1]
    }
  }
  convertToCascaderItem(data: any[]): CascaderItem[] {
    return data.map(item => {
      let cascaderItem: CascaderItem = {
        label: item.equipmentCategoryName,
        value: item.equipmentCategoryId,
      };
      if (item.subEquipmentCategories) {
        cascaderItem.children = this.convertToCascaderItem(item.subEquipmentCategories);
      }
      return cascaderItem;
    });
  }//转换数据格式为华为库练级菜单的数据格式
  onChanges($event: string | any[]){
    this.EquiomentCategory.parentEquipmentCategoryId = $event[$event.length-1]
  }
}
